package ch.sv7.tool.dbmanager.db;

public class FilePatternManager {

	public static final String TABLENAME_KEYWORD = "TABLENAME";

	public static final String SCHEMA_KEYWORD = "SCHEMA";

	public static final String DEFAULT_FILE_PATTERN = "TABLENAME";

	public FilePatternManager() {
	}

	public static String getFilename(String tablename, String schema, String pattern) {
		String result = pattern;
		if (result == null)
			result = "TABLENAME";
		result = replaceToken(result, "TABLENAME", tablename);
		result = replaceToken(result, "SCHEMA", schema);
		return result;
	}

	private static String replaceToken(String str, String pattern, String replace) {
		if (str == null || pattern == null || replace == null)
			return str;
		int pos = str.indexOf(pattern);
		if (pos == -1)
			return str;
		else
			return str.substring(0, pos) + replace + str.substring(pos + pattern.length());
	}
}
